* Load File
import delimited "/Users/slajp8/Downloads/Monarchism in the UK/IE data RR.csv", encoding(ISO-8859-1)

* Recode age
recode agegroup 17=15

* Create Dummy Variables for Country
gen england = .
replace england=1 if country=="England"
replace england=0 if country!="England"
gen wales = .
replace wales=1 if country=="Wales"
replace wales=0 if country!="Wales"
gen scotland = .
replace scotland=1 if country=="Scotland"
replace scotland=0 if country!="Scotland"

* Destring variables
replace educ="." if educ=="NA"
destring educ, replace
replace class="." if class=="NA"
destring class, replace
replace female="." if female=="NA"
destring female, replace
replace nhsapproval="." if nhsapproval=="NA"
destring nhsapproval, replace
replace trustgov="." if trustgov=="NA"
destring trustgov, replace
replace trustmps="." if trustmps=="NA"
destring trustmps, replace
replace lr="." if lr=="NA"
destring lr, replace
replace al="." if al=="NA"
destring al, replace

* Make Age and Period Into Strings
tostring agegroup, gen(agegroup1)
tostring periodgroup, gen(periodgroup1)

* Run Main Analyses
apc_ie monarchism wales scotland [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
apc_ie abolition wales scotland [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)

* Run Analyses for Other Institutions
** NHS
apc_ie nhsapproval wales scotland [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
** Government Trust
apc_ie trustgov wales scotland [aweight=weight] if age>=20 & age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
** MP Trust
apc_ie trustmps wales scotland [aweight=weight] if age>=20 & age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)

* Run Analyses Controlling for Other Factors
** Socio-Demographics
apc_ie monarchism wales scotland educ class female [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
apc_ie abolition wales scotland educ class female [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
** Socio-Demographics + Ideology
apc_ie monarchism wales scotland educ class female lr al [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
apc_ie abolition wales scotland educ class female lr al [aweight=weight] if age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
** Socio-Demographics + Trust
apc_ie monarchism wales scotland educ class female trustgov [aweight=weight] if age>=20 & age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
apc_ie abolition wales scotland educ class female trustgov [aweight=weight] if age>=20 & age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
** Socio-Demographics + Ideology + Trust
apc_ie monarchism wales scotland educ class female lr al trustgov [aweight=weight] if age>=20 & age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
apc_ie abolition wales scotland educ class female lr al trustgov [aweight=weight] if age>=20 & age<=80, age(agegroup) period(periodgroup) family(gaussian) link(identity)
